package com.me.jingdongshop.ui.activity;

import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.me.common.base.BaseActivity;
import com.me.jingdongshop.R;
import com.me.jingdongshop.ui.adapter.TestMyIndentItemAdapter;

/**
 * Created by Administrator on 2017/5/6.
 * 我的订单页
 */

public class MyIndentActivity extends BaseActivity {
    private ImageView imgBack;
    private ImageView imgAddAccount;
    private TextView tvTitle;
    private Button btnNowIndent;
    private Button btnBeforeIndent;
    private Button btnCancelIndent;
    private GradientDrawable mNowGradient;
    private GradientDrawable mBeforeGradient;
    private GradientDrawable mCancelGradient;
    private ListView lvIndentItem;
    private FrameLayout flIndentDetail;


    @Override
    public int getLayoutRes() {
        return R.layout.my_indent;
    }

    @Override
    public void initView() {


        imgBack = (ImageButton) findViewById(R.id.img_back);
        tvTitle = (TextView) findViewById(R.id.tv_title);
        btnNowIndent = (Button) findViewById(R.id.btn_now_indent);
        btnBeforeIndent = (Button) findViewById(R.id.btn_before_indent);
        btnCancelIndent = (Button) findViewById(R.id.btn_cancel_indent);
        flIndentDetail = (FrameLayout) findViewById(R.id.fl_indent_detail);
        lvIndentItem = (ListView) findViewById(R.id.lv_indent_item);
        initDefaultView();//默认显示，回显


    }

    /**
     * 默认显示/回显
     */
    private void initDefaultView() {
        //更改shape属性的对象
        mNowGradient = (GradientDrawable) btnNowIndent.getBackground();
        mBeforeGradient = (GradientDrawable) btnBeforeIndent.getBackground();
        mCancelGradient = (GradientDrawable) btnCancelIndent.getBackground();
        //设置进入的默认颜色
        mNowGradient.setColor(Color.parseColor("#FF304E"));
        mBeforeGradient.setColor(Color.parseColor("#CECECE"));
        mCancelGradient.setColor(Color.parseColor("#CECECE"));
//    默认显示的数据
        TestMyIndentItemAdapter adapter = new TestMyIndentItemAdapter();
        lvIndentItem.setAdapter(adapter);//目前是假数据，和使用的是测试Adapter
    }

    @Override
    public void initListener() {

    }

    @Override
    public void initData() {

    }

    @Override
    public void onClick(View v, int id) {


        switch (id) {
            case R.id.img_back:
                showToast("返回");
                finish();
                break;
            case R.id.btn_now_indent:
                showToast("十分钟之内的订单");
                if (btnNowIndent.isClickable()) {
                    //GradientDrawable可以设置shape里面的属性---通过代码完成
                    mNowGradient.setColor(Color.parseColor("#FF304E"));
                    mBeforeGradient.setColor(Color.parseColor("#CECECE"));
                    mCancelGradient.setColor(Color.parseColor("#CECECE"));

//                    通过更改shape背景图片完成---改变点击的对应Button颜色
//                    tvNowIndent.setBackgroundResource(R.drawable.my_indent_item_left_checked);
//                    tvBeforeIndent.setBackgroundResource(R.drawable.my_indent_item_center_normal);
//                    tvCancelIndent.setBackgroundResource(R.drawable.my_indent_item_center_normal);


                    TestMyIndentItemAdapter adapter = new TestMyIndentItemAdapter();
                    lvIndentItem.setAdapter(adapter);//目前是假数据，和使用的是测试Adapter
//                    mAdapter.notifyDataSetChanged();
                }

                break;
            case R.id.btn_before_indent:
                showToast("现在的订单");
                if (btnBeforeIndent.isClickable()) {
                    mNowGradient.setColor(Color.parseColor("#CECECE"));
                    mBeforeGradient.setColor(Color.parseColor("#FF304E"));
                    mCancelGradient.setColor(Color.parseColor("#CECECE"));
//        暂时
               flIndentDetail.removeAllViews();

                }

                break;
            case R.id.btn_cancel_indent:
                showToast("取消订单");
                if (btnCancelIndent.isClickable()) {
                    mNowGradient.setColor(Color.parseColor("#CECECE"));
                    mBeforeGradient.setColor(Color.parseColor("#CECECE"));
                    mCancelGradient.setColor(Color.parseColor("#FF304E"));
                    //        暂时
                    flIndentDetail.removeAllViews();
                }
                break;


        }


    }


    @Override
    public void onHttpSuccess(int reqType, Message msg) {

    }

    @Override
    public void onHttpError(int reqType, String error) {

    }
}
